﻿using AdminManagement.Dict;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace AdminManagement
{
    public class AdminManagementBackgroundService : BackgroundService
    {
        private readonly IRepository<SysDictData> repository;
        private readonly IMemoryCache memoryCache;

        public AdminManagementBackgroundService(IRepository<SysDictData> repository, IMemoryCache memoryCache)
        {
            this.repository = repository;
            this.memoryCache = memoryCache;
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var list = await repository.GetListAsync(m => m.Status == Status.Enable);
            memoryCache.Set(nameof(SysDictService.CacheQuery), list);
        }
    }
}
